package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwPlatformAccount;
import com.ruoyi.system.service.IGwPlatformAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台账号管理Controller
 *
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/system/platform")
public class GwPlatformAccountController extends BaseController
{
    @Autowired
    private IGwPlatformAccountService gwPlatformAccountService;

    /**
     * 查询平台账号管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwPlatformAccount gwPlatformAccount)
    {
        startPage();
        List<GwPlatformAccount> list = gwPlatformAccountService.selectGwPlatformAccountList(gwPlatformAccount);
        return getDataTable(list);
    }

    /**
     * 查询平台账号管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:list')")
    @GetMapping("/myEnterpriseList")
    public TableDataInfo myEnterpriseList(GwPlatformAccount gwPlatformAccount)
    {
        startPage();
        List<GwPlatformAccount> list = gwPlatformAccountService.myEnterpriseList(gwPlatformAccount);
        return getDataTable(list);
    }

    /**
     * 导出平台账号管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:export')")
    @Log(title = "平台账号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwPlatformAccount gwPlatformAccount)
    {
        List<GwPlatformAccount> list = gwPlatformAccountService.selectGwPlatformAccountList(gwPlatformAccount);
        ExcelUtil<GwPlatformAccount> util = new ExcelUtil<GwPlatformAccount>(GwPlatformAccount.class);
        util.exportExcel(response, list, "平台账号管理数据");
    }

    /**
     * 获取平台账号管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gwPlatformAccountService.selectGwPlatformAccountById(id));
    }

    /**
     * 新增平台账号管理
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:add')")
    @Log(title = "平台账号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwPlatformAccount gwPlatformAccount)
    {

        return gwPlatformAccountService.insertGwPlatformAccount(gwPlatformAccount);
    }

    /**
     * 修改平台账号管理
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:edit')")
    @Log(title = "平台账号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwPlatformAccount gwPlatformAccount)
    {
        return toAjax(gwPlatformAccountService.updateGwPlatformAccount(gwPlatformAccount));
    }

    /**
     * 删除平台账号管理
     */
//    @PreAuthorize("@ss.hasPermi('system:platform:remove')")
    @Log(title = "平台账号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gwPlatformAccountService.deleteGwPlatformAccountByIds(ids));
    }

    /**
     * 变更用户状态
     * @Date 下午 4:09:16 2025/5/29
     * @param gwPlatformAccount
     * @return 结果
     **/
    @Log(title = "平台账号管理", businessType = BusinessType.INSERT)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GwPlatformAccount gwPlatformAccount)
    {
        return toAjax(gwPlatformAccountService.changeStatus(gwPlatformAccount));
    }

    /**
     * 重置密码
     * @Date 下午 4:09:16 2025/5/29
     * @param gwPlatformAccount
     * @return 结果
     **/
    @Log(title = "平台账号管理", businessType = BusinessType.INSERT)
    @PostMapping("/resetPassword")
    public AjaxResult resetPassword(@RequestBody GwPlatformAccount gwPlatformAccount)
    {
        return toAjax(gwPlatformAccountService.resetPassword(gwPlatformAccount));
    }
}
